package com.sxfq.loansupermarket.backsystem.modular.marketing.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.marketing.dao.SecondDevelopmentDao;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.ApprovalProcessInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.SearchApprovalProcessInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.service.ISecondDevelopmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class SecondDevelopmentServiceImpl implements ISecondDevelopmentService {
    @Autowired
    private SecondDevelopmentDao dao;

    @Override
    public List<ApprovalProcessInfo> selectPageListByGetMap(Page<ApprovalProcessInfo> page, SearchApprovalProcessInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())){
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getOutpatientName())){
            params.put("outpatientName", searchInfo.getOutpatientName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getResult())){
            params.put("result", searchInfo.getResult());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        params.put("channelAuditLevel", "a.channel_audit_level = "+ShiroKit.getUser().getChannelAuditLevel()+"");
        params.put("userName", ShiroKit.getUser().getAccount());
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPage(page, params);
    }

    @Override
    public int getQueryPagesGetMapCount(Page<ApprovalProcessInfo> page, SearchApprovalProcessInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())){
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getOutpatientName())){
            params.put("outpatientName", searchInfo.getOutpatientName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getResult())){
            params.put("result", searchInfo.getResult());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        params.put("channelAuditLevel", "a.channel_audit_level = "+ShiroKit.getUser().getChannelAuditLevel()+"");
        params.put("userName", ShiroKit.getUser().getAccount());
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPageCount(page, params);
    }

    @Override
    public int getQueryPagesGetMapCountYi(Page<ApprovalProcessInfo> page, SearchApprovalProcessInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())){
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getOutpatientName())){
            params.put("outpatientName", searchInfo.getOutpatientName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getResult())){
            params.put("result", searchInfo.getResult());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getExamineStartTime())) {
            params.put("examineStartTime", searchInfo.getExamineStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getExamineEndTime())) {
            params.put("examineEndTime", searchInfo.getExamineEndTime());
        }
        params.put("userName", ShiroKit.getUser().getAccount());
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPageCountYi(page, params);
    }

    @Override
    public List<ApprovalProcessInfo> selectPageListByGetMapYi(Page<ApprovalProcessInfo> page, SearchApprovalProcessInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())){
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getOutpatientName())){
            params.put("outpatientName", searchInfo.getOutpatientName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getResult())){
            params.put("result", searchInfo.getResult());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getExamineStartTime())) {
            params.put("examineStartTime", searchInfo.getExamineStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getExamineEndTime())) {
            params.put("examineEndTime", searchInfo.getExamineEndTime());
        }
        params.put("userName", ShiroKit.getUser().getAccount());
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPageYi(page, params);
    }
}